home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / inter54e.zip / INTSUM16.ZIP / DVIDEO.ASM < prev    next >
Assembly Source File  |  1996-10-13  |  7KB  |  243 lines

  1. ;*****************************************************************
  2. ;  DVIDEO.ASM - Video functions for INTSUM.EXE                    
  3. ;                                                                 
  4. ;  Copyright (c) 1996 Daniel D. Miller                            
  5. ;                                                                 
  6. ;  Last Update: 10-14-95 11:37am                                  
  7. ;*****************************************************************
  8.         .model  compact,c
  9.  
  10.         .data
  11. curx            word    0
  12. cury            word    0
  13. VideoSeg        word    0B800h
  14.         public  screen_rows
  15. screen_rows     word    0
  16.         public  screen_cols
  17. screen_cols     word    0
  18.  
  19.         .code
  20.  
  21. ;  void select_video_seg(unsigned vseg) ;
  22. ;  If vseg == 0, this routine will check video mode to
  23. ;  determine video segment (if mode == 7, vseg = B000 else B800).
  24. ;  If vseg != 0, VideoSeg will be set to vseg.  No checking
  25. ;  for invalid values is done, so make sure you don't set bad data.
  26. select_video_seg proto c vseg:word
  27. select_video_seg proc  c uses ax bx vseg:word
  28.         mov     ax,vseg
  29.         cmp     ax,0
  30.         je      read_video_mode
  31.         ;  vseg is non-zero; copy it to VideoSeg
  32.         mov     VideoSeg,ax
  33.         ret
  34.  
  35. read_video_mode:
  36.         mov     ah,0Fh
  37.         int     10h
  38.         cmp     al,7
  39.         jne     setB800
  40.         mov     ax,0B000h
  41.         mov     VideoSeg,ax
  42.         ret
  43. setB800:
  44.         mov     ax,0B800h
  45.         mov     VideoSeg,ax
  46.         ret
  47.         
  48. select_video_seg endp
  49.  
  50. ;  unsigned get_video_seg(void) ;
  51. get_video_seg proto c
  52. get_video_seg proc  c
  53.         mov     ax,VideoSeg
  54.         ret
  55. get_video_seg endp
  56.  
  57. ;  uchar get_char_attr(void) ;
  58. get_char_attr proto c
  59. get_char_attr proc  c uses bx
  60.         mov     ah,8
  61.         mov     bh,0
  62.         int     10h
  63.         mov     al,ah
  64.         ret
  65. get_char_attr endp
  66.  
  67. ;  void clear_display(uchar cattr) ;
  68. clear_display proto c attr:byte
  69. clear_display proc  c uses es di cx ax attr:byte
  70.         ;  point at video buffer
  71.         mov     ax,VideoSeg
  72.         mov     es,ax
  73.         xor     di,di
  74.  
  75.         ;  calculate screen size in words
  76.         mov     ax,screen_rows
  77.         mov     cx,screen_cols
  78.         mul     cx
  79.         mov     cx,ax
  80.  
  81.         ;  get fill data
  82.         mov     al,' '
  83.         mov     ah,attr
  84.  
  85.         ;  fill the screen
  86.         rep     stosw
  87.         ret
  88. clear_display endp
  89.  
  90. ;  void get_vsize(void) ;
  91. get_vsize proto c
  92. get_vsize proc  c uses ax bx cx si
  93.         push    ds      ; DATA SEGMENT IS NOW INVALID!!
  94.         mov     ax,0
  95.         mov     ds,ax
  96.         mov     si,044Ah        ; address of screen columns
  97.         mov     ax,ds:[si]
  98.         mov     bx,ax
  99.         mov     si,0484h        ; address of screen rows
  100.         mov     al,ds:[si]
  101.         xor     ah,ah
  102.         inc     ax      ; BIOS data is base-0
  103.         mov     cx,ax
  104.         pop     ds      ; restore data segment
  105.         mov     screen_cols,bx
  106.         mov     screen_rows,cx
  107.         ret
  108. get_vsize endp
  109.  
  110. ;  void dgotoxy(unsigned x, unsigned y) ;
  111. dgotoxy proto c  x:word, y:word
  112. dgotoxy proc  c  uses ax x:word, y:word
  113.         mov     ax,x
  114.         mov     curx,ax
  115.         mov     ax,y
  116.         mov     cury,ax
  117.         ret
  118. dgotoxy endp
  119.  
  120. ;  void dprintc(unsigned x, unsigned y, uchar attr, char outchr) ;
  121. dprintc proto C x:word, y:word, attr:byte, outchr:byte
  122. dprintc proc  C uses ax bx es di x:word, y:word, attr:byte, outchr:byte
  123.         mov     ax,screen_cols
  124.         mov     bx,y
  125.         mul     bx      ; dx:ax <- ax * bx = screen_cols * y
  126.         add     ax,x
  127.         shl     ax,1    ;  ax <- (screen_width * 2 * y) + 2 * x
  128.         ;  AX now contains offset to video destination
  129.         mov     di,ax   
  130.         mov     ax,VideoSeg
  131.         mov     es,ax   ;  ES:DI -> video dest
  132.  
  133.         mov     ah,attr
  134.         mov     al,outchr
  135.         mov     es:[di],ax
  136.         ;stosw           ;  ES:[DI++] <- AX
  137.         ret
  138. dprintc endp
  139.  
  140. ;  void dprints(unsigned x, unsigned y, uchar attr, char* outstr) ;
  141. dprints proto C x:word, y:word, attr:byte, outstr:far ptr byte
  142. dprints proc  C uses ax bx es di ds si x:word, y:word, attr:byte, outstr:far ptr byte
  143.         mov     ax,screen_cols
  144.         mov     bx,y
  145.         mul     bx      ; dx:ax <- ax * bx = screen_cols * y
  146.         add     ax,x
  147.         shl     ax,1    ;  ax <- (screen_width * 2 * y) + 2 * x
  148.         ;  AX now contains offset to video destination
  149.         mov     di,ax   
  150.         mov     ax,VideoSeg
  151.         mov     es,ax   ;  ES:DI -> video dest
  152.  
  153.         lds     si,outstr       ; DS:SI -> string to display
  154.         mov     ah,attr
  155. dpr_loop:
  156.         mov     al,ds:[si]
  157.         inc     si
  158.         ;lodsb           ;  AL <- DS:[SI++]
  159.         cmp     al,0
  160.         je      dpr_done
  161.         mov     es:[di],ax
  162.         ;stosw           ;  ES:[DI++] <- AX
  163.         inc     di
  164.         inc     di
  165.         jmp     dpr_loop
  166.  
  167. dpr_done:
  168.         ret
  169. dprints endp
  170.  
  171. ; void mark_cursor_line(unsigned row, uchar attr) ;
  172. mark_cursor_line proto C row:word, attr:byte
  173. mark_cursor_line proc  C uses ax bx cx es di row:word, attr:byte
  174.         mov     ax,screen_cols
  175.         shl     ax,1    ; convert byte offset to word offset
  176.         mov     bx,row
  177.         mul     bx      ; dx:ax <- ax * bx = screen_cols * y
  178.         ;  AX now contains offset to video destination
  179.         mov     di,ax   
  180.         mov     ax,VideoSeg
  181.         mov     es,ax   ;  ES:DI -> video dest
  182.         inc     di      ; point to attribute byte
  183.  
  184.         mov     al,attr
  185.         mov     cx,80   ;  change attribute
  186. @@:     mov     es:[di],al
  187.         inc     di
  188.         inc     di      ; skip character position
  189.         loop    @B
  190.         ret
  191. mark_cursor_line endp
  192.  
  193.  
  194. ;********************************************************************
  195. ;include keycodes.h with get_key() and key_hit()  
  196.  
  197. ;********************************************************************
  198. ; unsigned get_key(void)
  199. ;********************************************************************
  200. get_key proc
  201.         mov     ah,0
  202.         int     16h
  203.         ret
  204. get_key endp
  205.  
  206. ;**********************************************************
  207. ; int key_hit(void)
  208. ;**********************************************************
  209. key_hit proc
  210.         mov     ah,1
  211.         int     16h
  212.         jz      key_hit_not
  213.         mov     ax,1
  214.         ret
  215. key_hit_not:
  216.         mov     ax,0
  217.         ret
  218. key_hit endp
  219.  
  220. ; //**********************************************************
  221. ; void hide_cursor(void)
  222. hide_cursor proc uses ax bx dx
  223.         mov     dh,100  ; row
  224.         mov     dl,200  ; column
  225.         mov     bh,0
  226.         mov     ah,2
  227.         int     10h
  228.         ret
  229. hide_cursor endp
  230.  
  231. ; //**********************************************************
  232. ; void home_cursor(void)
  233. home_cursor proc uses ax bx dx
  234.         mov     dh,0    ; row
  235.         mov     dl,2    ; column
  236.         mov     bh,0
  237.         mov     ah,2
  238.         int     10h
  239.         ret
  240. home_cursor endp
  241.  
  242.         end
  243.